package com.zgl.modules.wallet.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zgl.modules.wallet.entity.WalletEntity;
import com.zgl.modules.wallet.mapper.WalletMapper;
import com.zgl.modules.wallet.service.WalletService;
import com.zgl.utils.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WalletServiceImpl implements WalletService {
    @Resource
    WalletMapper walletMapper;

    public R savaOne(WalletEntity cardEntity) {
        if (1 == walletMapper.insert(cardEntity)) {
            return R.success();
        } else {
            return R.error("操作失败");
        }
    }

    public R removeOne(Integer id) {
        if (1 == walletMapper.deleteById(id)) {
            return R.success();
        } else {
            return R.error("操作失败");
        }
    }

    public R modifyOne(WalletEntity walletEntity) {
        if (walletMapper.updateById(walletEntity) == 1) {
            return R.success();
        } else {
            return R.error();
        }

    }

    public R getOne(Integer id) {
        WalletEntity WalletEntity = walletMapper.selectById(id);
        return R.success(WalletEntity);
    }

    @Override
    public R getCardByUserId(Integer id) {
        QueryWrapper<WalletEntity> queryWrapper = new QueryWrapper<>() ;
        queryWrapper.eq("userid",id);
      WalletEntity walletEntity = walletMapper.selectOne(queryWrapper);
        return R.success(walletEntity);
    }
}
